package com.sztz.batch;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobInstance;

/**
 * JOB执行监听器
 * @author yzy
 * @date 2022/8/17 15:12
 */
@Slf4j
public class MyJobListener implements JobExecutionListener {

    @Override
    public void beforeJob(JobExecution jobExecution) {
        JobInstance jobInstance = jobExecution.getJobInstance();
        log.info("job开始，id={},create={}",jobInstance.getInstanceId(),jobInstance.getJobName());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        JobInstance jobInstance = jobExecution.getJobInstance();
        log.info("job结束，job执行状态={}，id={},create={}",jobExecution.getStatus().getBatchStatus().name(),jobInstance.getInstanceId(),jobInstance.getJobName());
    }
}
